package com.qiandw.entity.security;

import lombok.Data;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.One;

import javax.persistence.*;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author coxx
 */
@Data
@Entity
@Table(name = "sys_authority")
public class Authority {
    @Id
    private String id;
    private String parentId;
    private String name;
    private String url;
    private Integer authType;
    private String orderNumber;
    private Integer status;
    @OneToOne
    @JoinColumn(name = "sysAuthority_id")
    private Authority parent;
    @OneToMany
    @JoinTable(name = "auth_relation",
            joinColumns = @JoinColumn(name = "sysAuthority_parentId"),
            inverseJoinColumns = @JoinColumn(name = "sysAuthority_id")
    )
    private List<Authority> children;
    public List<String> getChildrenId(){
        return Objects.isNull(children) ? null : children.stream().map(Authority::getId).collect(Collectors.toList());
    }
    private String description;
}
